package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.fly.domain.AllOrder;
import com.ruoyi.fly.domain.AppletMember;
import com.ruoyi.fly.domain.AppletProductOrder;
import com.ruoyi.fly.domain.vo.*;
import com.ruoyi.fly.mapper.AppletProductOrderMapper;
import com.ruoyi.fly.service.AppletProductOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productOrder")
@Api(tags = "产品订单管理")
public class AppletProductOrderController extends BaseController {

    @Autowired
    private AppletProductOrderService appletProductOrderService;


    /**
     * 查询订单收入
     */
    @ApiOperation(value = "查询订单收入")
    @PostMapping("/orderIncome")
    public R<OrderIncomeVo> getOrderIncome(@RequestBody OrderVo orderVo) {
        OrderIncomeVo orderIncome = appletProductOrderService.getOrderIncome(orderVo);
        return R.ok(orderIncome);
    }

    /**
     * 查询产品和服务订单列表
     */
    @ApiOperation(value = "查询产品和服务订单列表")
    @PostMapping("/productServerList")
    public R<AllOrder> productServerList(@RequestBody AllOrderVo allOrderVo) {
        return appletProductOrderService.selectAppletProductServerOrderList(allOrderVo);
    }

    /**
     * 查询产品订单列表
     */
    //@ApiOperation(value = "查询产品订单列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody AppletProductOrderSearchVo appletProductOrder) {
        PageDomain pageDomain = new PageDomain();
        BeanUtils.copyProperties(appletProductOrder, pageDomain);
        startPage(pageDomain);
        List<ProductOrderVo> list = appletProductOrderService.selectAppletProductOrderList(appletProductOrder);
        return getDataTable(list);
    }


    /**
     * 根据产品订单id获取产品订单详细信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据产品订单id获取产品订单详细信息", response = ProductOrderVo.class)
    @GetMapping(value = "/select/{id}")
    public R<ProductOrderVo> getInfo(@PathVariable("id") String id) {
        if (id == null) {
            return R.fail("参数错误");
        }
        if (appletProductOrderService.selectAppletProductOrderById(id) == null) {
            return R.fail("订单不存在");
        }
        return R.ok(appletProductOrderService.selectAppletProductOrderById(id));
    }

//    /**
//     * 根据条件查询产品订单
//     */
//    //@ApiOperation(value = "根据条件查询产品订单")
//    @PostMapping("/selectOrder")
//    public R selectProductOrder(@RequestBody ProductOrderQueryVo productOrderQueryVo) {
//        return R.ok(appletProductOrderService.selectAppletProductOrder(productOrderQueryVo));
//    }

    /**
     * 添加快递单号
     *
     * @param appletProductOrderVo
     * @return
     */
    @ApiOperation(value = "添加快递单号")
    @PostMapping("/add")
    public R edit(@RequestBody AppletProductOrderVo appletProductOrderVo) {
        if (appletProductOrderVo.getOrderCode() == null || appletProductOrderVo.getExpressNo() == null) {
            return R.fail("参数不能为空");
        }
        return appletProductOrderService.updateAppletProductOrder(appletProductOrderVo);
    }

    /**
     * 删除产品订单
     *
     * @param deleteVo
     * @return
     */
    @ApiOperation(value = "删除产品订单")
    @PostMapping("/delete")
    public R remove(@RequestBody DeleteVo deleteVo) {
        if (StringUtils.isEmpty(deleteVo.getIds())) {
            return R.fail("参数不能为空");
        }
        return appletProductOrderService.deleteAppletProductOrderByIds(deleteVo.getIds());
    }
}
